package net.ojbk.timeAxis.tool;

import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession; 
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class DBTool {
	public static SqlSessionFactory sessionFactory;
    
    static{
        try {
        	// 创建会话工厂
        	String resource = "SqlMapConfig.xml";
        	InputStream inputStream = Resources.getResourceAsStream(resource);
        	sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
    }
    
    //创建能执行映射文件中sql的sqlSession
    public static SqlSession getSession(){
        return sessionFactory.openSession();
    }
    


}
